home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 57131 / 57131.xpi / chrome / beefree.jar / content / beefree / beefree.protocol.js < prev    next >
Encoding:
JavaScript  |  2010-01-25  |  2.4 KB  |  79 lines

  1. /*
  2.     2009 - Copyright by Bee <http://www.honeybeenet.altervista.org>.
  3.     This program is free software; you can redistribute it and/or
  4.     modify it under the terms of the GNU General Public License
  5.     as published by the Free Software Foundation; either version 2
  6.     of the License, or (at your option) any later version.
  7.  
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.     GNU General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU General Public License
  14.     along with this program; if not, write to the Free Software
  15.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17.  
  18. function beefree_is_protocol(address, protocol)
  19. {
  20.     if(protocol.length > address.length)
  21.         return false;
  22.     address = address.toLowerCase();
  23.     return address.indexOf(protocol.toLowerCase()) == 0;
  24. }
  25.  
  26. function beefree_is_protocol_web(address)
  27. {
  28.     return beefree_is_protocol(address, "http://") || beefree_is_protocol(address, "https://");
  29. }
  30.  
  31. function beefree_is_hyperlink(address)
  32. {
  33.     if(address.length == 0)
  34.         return false;
  35.     if( beefree_is_protocol_web(address) || 
  36.         beefree_is_protocol(address, "javascript:") ||
  37.         address.indexOf(":") < 0)
  38.         return true;
  39.     var index = address.indexOf("?");
  40.     if(index >= 0)
  41.         address = address.substr(0, index);
  42.     return address.indexOf(":") < 0 || address.indexOf(":") > 10;
  43. }
  44.  
  45. function beefree_is_anchor(address)
  46. {
  47.     if(address.length == 0)
  48.         return false;
  49.     return address.substr(0, 1) == "#";
  50. }
  51.  
  52. function beefree_is_anchor_magic(address, base)
  53. {
  54.     if(address.length == 0)
  55.         return false;
  56.     return (address.substr(0, 1) == "#") || 
  57.            (address.substr(0, 1+base.length) == base + "#");
  58. }
  59.  
  60. function beefree_make_uri_object(aURL, aOriginCharset, aBaseURI)
  61. {  
  62.     //https://developer.mozilla.org/en/nsIURI
  63.     var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);  
  64.     return ioService.newURI(aURL, aOriginCharset, aBaseURI);  
  65. }  
  66.  
  67. function beefree_host_from_address_ext(url, charset /* = null */)
  68. {
  69.     var locURI = beefree_make_uri_object(url, charset, null);
  70.     return locURI.asciiHost;
  71. }
  72.  
  73. function beefree_host_from_address(url)
  74.     return beefree_host_from_address_ext(url, null);
  75. }
  76.  
  77.  
  78.